package net.wofly.cashier.table.validator;

import net.wofly.cashier.table.domain.Table;
import org.apache.commons.lang3.StringUtils;

/**
 * Created by Administrator on 2017/11/5.
 */
public class TableValidator {
    /**
     * 换行符
     */
    private static String lineSeparator = System.getProperty("line.separator");

    public static String validateAddTableParams(Table table) {
        StringBuffer stringBuffer = new StringBuffer();
        if (table == null) {
            stringBuffer.append("餐桌信息不能为空").append(lineSeparator);
        } else {
            if (StringUtils.isBlank(table.getTableID())) {
                stringBuffer.append("餐桌编码不能为空").append(lineSeparator);
            }

            if (StringUtils.isBlank(table.getTableName())) {
                stringBuffer.append("餐桌名称不能为空").append(lineSeparator);
            }

            if (table.getTableForNum() == null) {
                stringBuffer.append("餐桌就餐人数不能为空").append(lineSeparator);
            }

            if (table.getTableStatus() == null) {
                stringBuffer.append("餐桌状态不能为空").append(lineSeparator);
            }
        }
        return stringBuffer.toString();
    }

    public static String validateDelTableParams(String tableID) {
        StringBuffer stringBuffer = new StringBuffer();

        if (StringUtils.isBlank(tableID)) {
            stringBuffer.append("餐桌编码不能为空").append(lineSeparator);
        }

        return stringBuffer.toString();
    }

    public static String validateGetAllTableParams(Integer status) {
        StringBuffer stringBuffer = new StringBuffer();

        if (status == null) {
            stringBuffer.append("状态不能为空").append(lineSeparator);
        }

        return stringBuffer.toString();
    }

    public static String validateUpdateTableParams(Table table) {
        return validateAddTableParams(table);
    }

    public static String validateUpdateTableStatusParams(String tableID, Integer tableStatus) {
        StringBuffer stringBuffer = new StringBuffer();

        if (StringUtils.isBlank(tableID)) {
            stringBuffer.append("餐桌编码不能为空").append(lineSeparator);
        }

        if (tableStatus == null) {
            stringBuffer.append("餐桌状态不能为空").append(lineSeparator);
        }

        return stringBuffer.toString();
    }
}
